package auto.app.controller;


import auto.app.controller.from.BeforeAssertion.BeforeAssertionFrom;
import auto.app.controller.from.BeforeAssertion.BeforeAssertionUpdateFrom;
import auto.app.controller.info.BeforeAssertion.BeforeAssertionInfo;
import auto.app.controller.info.TypeListInfo;
import auto.app.enums.AssertMethodsType;
import auto.app.enums.ParameType;
import auto.app.exetion.HibernateExetion;
import auto.app.exetion.MainExection;
import auto.app.model.BeforeAssertion;
import auto.app.service.BeforeAssertionService;
import auto.app.util.CommonUtil;
import auto.app.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨森
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/beforeAssertion")
@Api(value = "断言",tags = "断言")
public class BeforeAssertionController {
    @Autowired
    private BeforeAssertionService beforeAssertionService;

    @PostMapping(name = "新增断言")
    @ApiOperation(value = "新增断言",notes = "新增断言")
    public Result<Boolean> beforeAssertionAdd(@RequestBody BeforeAssertionFrom beforeAssertionFrom) throws MainExection {
        //去除字符串前后的空格
        beforeAssertionFrom.setExtractExpression(beforeAssertionFrom.getExtractExpression().trim());
        Boolean aBoolean = beforeAssertionService.beforeAssertionAdd(beforeAssertionFrom);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }
    //获取参数类型
    @GetMapping(value = "/list/type",name = "获取断言方法类型")
    @ApiOperation(value = "获取断言方法类型",notes = "获取断言方法类型")
    public BeforeAssertionInfo  beforeAssertionMethodType(){
        List<Map<String, String>> maps = AssertMethodsType.toList();
        BeforeAssertionInfo beforeAssertionInfo=new BeforeAssertionInfo();
        beforeAssertionInfo.setCode(200);
        beforeAssertionInfo.setMsg("请求成功");
        beforeAssertionInfo.setData(maps);
        return beforeAssertionInfo;
    }
    @PutMapping(name = "修改断言")
    @ApiOperation(value = "修改断言",notes = "修改断言")
    public Result<Boolean> beforeAssertionUpdated(@RequestBody BeforeAssertionUpdateFrom beforeAssertionUpdateFrom) throws MainExection {
        Boolean aBoolean = beforeAssertionService.beforeAssertionUpdate(beforeAssertionUpdateFrom);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }

    @GetMapping(value = "/deatil/{automaticId}",name = "查看断言详情")
    @ApiOperation(value = "查看断言详情",notes = "查看断言详情")
    public Result<BeforeAssertion> beforeAssertionDetail(@PathVariable Integer automaticId) throws MainExection {
        BeforeAssertion beforeAssertion = beforeAssertionService.beforeAssertionDetail(automaticId);
        return Result.getInstance(BeforeAssertion.class).setData(beforeAssertion);
    }
    @GetMapping(value = "/list/{caseId}",name = "查看该测试用例下的断言")
    @ApiOperation(value = "查看该测试用例下的断言",notes = "查看该测试用例下的断言")
    public Result<List<BeforeAssertion>> beforeAssertionList(@PathVariable Integer caseId) throws MainExection {
        List<BeforeAssertion> beforeAssertions = beforeAssertionService.beforeAssertionList(caseId);
        return Result.getInstanceList(BeforeAssertion.class).setData(beforeAssertions);
    }
    @DeleteMapping(value = "/{automaticId}",name = "删除断言")
    @ApiOperation(value = "删除断言",notes = "删除断言")
    public Result<Boolean> beforeAssertionDelete(@PathVariable Integer automaticId ) throws MainExection {
        Boolean aBoolean = beforeAssertionService.beforeAssertionDelete(automaticId);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }

}

